/**
 * Created by ThinkPad on 2021-04-26.
 */

module.exports = class BaseError {
    constructor() {
            this._SUCCESS = [0, "验证成功"]
        // 鉴权相关
            this._AUTH					= [10000, "鉴权异常"]
            this._AUTH_JWT					= [10001, "jwt校验异常"]
            this._AUTH_OAUTH					= [10002, "oauth 验证异常"]
            this._AUTH_PARAM				= [10003, "参数验证异常"]

            this._AUTH_PARAM_RESPONSE				= [-10003, "响应参数验证异常"]

            //LANQ_ENCRYPT相关错误请求方
            this._ENCRYPT				= [10010, "安全校验异常"]
            this._ENCRYPT_APPID				= [10011, "appId不可用"]
            this._ENCRYPT_SIGN_FAIL				= [10012, "sign验证错误"]
            this._ENCRYPT_BIZ_TIME_INVALID				= [10013, "bizTime格式有误"]
            this._ENCRYPT_BIZ_TIME_FAIL				= [10014, "bizTime不在有效期范围内"]
            this._ENCRYPT_BIZ_SEQUENCE_ID_DUPLICATE				= [10015, "bizSequenceId重复"]
            this._ENCRYPT_DATA_DECODE_FAIL				= [10016, "数据解密失败"]
            this._ENCRYPT_DATA_DECODE_EMPTY				= [10017, "缺失加密字段"]
            this._ENCRYPT_DATA_DECODE_NOT_MATCHING				= [10018, "加密字段不匹配"]
            this._ENCRYPT_APPKEY				= [10019, "appKey校验失败"]

           //LANQ_ENCRYPT相关错误响应方
            this._ENCRYPT_RESPONSE				= [-10010, "响应安全校验异常"]
            this._ENCRYPT_SIGN_FAIL_RESPONSE				= [-10012, "响应sign验证错误"]
            this._ENCRYPT_DATA_DECODE_FAIL_RESPONSE				= [-10016, "响应数据解密失败"]

        //数据库相关
            this._DB				    =[20000, "数据库异常"]
            this._DB_REDIS				    =[20001, "Redis异常"]

        //服务端逻辑相关
            this._SERVER				    =[30000, "服务端业务异常"]

            //系统错误
            this._SERVICE_EXCEPTION				=[40001, "服务异常"]

    }

    static getInstance(){
        return new BaseError()
    }

    getError (code){
        const returnKey = Object.getOwnPropertyNames(this).filter(key=>{
            return this[key][0] == code
        })
        if(returnKey.length>0) return this[returnKey[0]].join(",")
        return returnKey
    }


    get ENCRYPT_APPKEY() {
        return this._ENCRYPT_APPKEY;
    }

    get ENCRYPT_DATA_DECODE_NOT_MATCHING() {
        return this._ENCRYPT_DATA_DECODE_NOT_MATCHING;
    }

    get ENCRYPT_DATA_DECODE_EMPTY() {
        return this._ENCRYPT_DATA_DECODE_EMPTY;
    }

    get ENCRYPT_RESPONSE() {
        return this._ENCRYPT_RESPONSE;
    }

    get ENCRYPT_SIGN_FAIL_RESPONSE() {
        return this._ENCRYPT_SIGN_FAIL_RESPONSE;
    }

    get ENCRYPT_DATA_DECODE_FAIL_RESPONSE() {
        return this._ENCRYPT_DATA_DECODE_FAIL_RESPONSE;
    }

    get AUTH_PARAM_RESPONSE() {
        return this._AUTH_PARAM_RESPONSE;
    }

    get SERVICE_EXCEPTION() {
        return this._SERVICE_EXCEPTION;
    }

    get SUCCESS() {
        return this._SUCCESS;
    }

    get AUTH() {
        return this._AUTH;
    }

    get AUTH_JWT() {
        return this._AUTH_JWT;
    }

    get AUTH_OAUTH() {
        return this._AUTH_OAUTH;
    }

    get AUTH_PARAM() {
        return this._AUTH_PARAM;
    }

    get ENCRYPT() {
        return this._ENCRYPT;
    }

    get ENCRYPT_APPID() {
        return this._ENCRYPT_APPID;
    }

    get ENCRYPT_SIGN_FAIL() {
        return this._ENCRYPT_SIGN_FAIL;
    }

    get ENCRYPT_BIZ_TIME_INVALID() {
        return this._ENCRYPT_BIZ_TIME_INVALID;
    }

    get ENCRYPT_BIZ_TIME_FAIL() {
        return this._ENCRYPT_BIZ_TIME_FAIL;
    }

    get ENCRYPT_BIZ_SEQUENCE_ID_DUPLICATE() {
        return this._ENCRYPT_BIZ_SEQUENCE_ID_DUPLICATE;
    }

    get ENCRYPT_DATA_DECODE_FAIL() {
        return this._ENCRYPT_DATA_DECODE_FAIL;
    }

    get DB() {
        return this._DB;
    }

    get DB_REDIS() {
        return this._DB_REDIS;
    }

    get SERVER() {
        return this._SERVER;
    }
}
